USE [loan]
GO
/****** Object:  StoredProcedure [dbo].[RedBalTest]    Script Date: 05/06/2013 15:02:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[AddOnTest]
AS
BEGIN

DECLARE @month INT = 4, @year INT = 2012, @interest INT = 1

SELECT 
	l.loan_no AS [Loan No],
	CONVERT(VARCHAR(9), l.start_date, 6) AS [Start Date],
	CONVERT(VARCHAR(9), l.end_date, 6) AS [End Date],
	l.principal AS [Amount],
	l.term AS [Term],
	l.period AS [Frequency],
	dbo.GetInterest_ED(@month, @year, @interest, l.start_date, l.end_date, l.principal, l.period) as [Apr 2012]	,
	dbo.GetInterest_ED(@month + 1, @year, @interest, l.start_date, l.end_date, l.principal, l.period) as [May 2012],
	dbo.GetInterest_ED(@month + 2, @year, @interest, l.start_date, l.end_date, l.principal, l.period) as [Jun 2012],
	dbo.GetInterest_ED(@month + 3, @year, @interest, l.start_date, l.end_date, l.principal, l.period) as [Jul 2012],
	dbo.GetInterest_ED(@month + 4, @year, @interest, l.start_date, l.end_date, l.principal, l.period) as [Aug 2012],
	dbo.GetInterest_ED(@month + 5, @year, @interest, l.start_date, l.end_date, l.principal, l.period) as [Sep 2012],
	dbo.GetInterest_ED(@month + 6, @year, @interest, l.start_date, l.end_date, l.principal, l.period) as [Oct 2012],
	dbo.GetInterest_ED(@month + 7, @year, @interest, l.start_date, l.end_date, l.principal, l.period) as [Nov 2012],
	dbo.GetInterest_ED(@month + 8, @year, @interest, l.start_date, l.end_date, l.principal, l.period) as [Dec 2012],
	dbo.GetInterest_ED(@month - 3, @year + 1, @interest, l.start_date, l.end_date, l.principal, l.period) as [Jan 2013],
	dbo.GetInterest_ED(@month - 2, @year + 1, @interest, l.start_date, l.end_date, l.principal, l.period) as [Feb 2013],
	dbo.GetInterest_ED(@month - 1, @year + 1, @interest, l.start_date, l.end_date, l.principal, l.period) as [Mar 2013],
	dbo.GetInterest_ED(@month, @year + 1, @interest, l.start_date, l.end_date, l.principal, l.period) as [Apr 2013]
FROM 
	loan AS l
ORDER BY
	l.start_date
END

-- exec AddOnTest
